package org.dormi.learn.product.domain.material.action;

import org.dormi.learn.domain.AbstractDomainAction;
import org.dormi.learn.domain.Tcode;
import org.dormi.learn.event.BaseEvent;
import org.dormi.learn.exp.CatalogedException;
import org.dormi.learn.product.domain.material.ModuleDependency;
import org.dormi.learn.product.domain.material.entity.Material;
import org.dormi.learn.product.domain.material.repo.MaterialRepository;
import org.dormi.learn.utils.TrackingUtils;

/**
 * 创建 material
 *
 * @author : dormi330
 * @version : 1.0
 */
public class CreateMaterialAction extends AbstractDomainAction<Material> {

    private static final Tcode MY_TCODE = Tcode.from(CreateMaterialAction.class);

    private MaterialRepository repository = ModuleDependency.instance().getMaterialRepository();

    /* === constructor === */
    /* === constructor === */
    /* === constructor === */

    public CreateMaterialAction(Material material) {
        super(material);
    }

    @Override
    protected void _processInternal() throws CatalogedException {
        TrackingUtils.debugTrace();
        input.checkIntegrity();

        repository.saveMaterial(input);
        addEvent(new BaseEvent(MY_TCODE.code(), input.getId(), input.toString()));
    }


    @Override
    public Tcode getTcode() {
        return MY_TCODE;
    }


    /* === internal biz code === */
    /* === internal biz code === */
    /* === internal biz code === */

}
